home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d8 / toes114g.arc / TOES.SLT < prev    next >
Text File  |  1991-05-21  |  42KB  |  1,211 lines

  1. // FIX the code which tests for SE on BBS asking More Y/N if more than
  2. //   one page of news
  3. // Add code to test for being reminded about subscriptions being due.
  4. //   this is in TOESDIAL, not here !
  5.  
  6. /////////////////////////////// TOES.SLT ////////////////////////////////////
  7. //                         Version 1.14 - April 1991
  8. //
  9. // Written by Ken Ironside of 5:491/1
  10. // Maintained by Allan Marillier of 5:491/1
  11.  
  12. // PLEASE - read (or at least skim) the docs. There are no user configurable
  13. //          variables, or anything in this file any more.
  14. //
  15. // OPUS -  Golden City Fido & Silver Express upload and download script.
  16. //
  17.  
  18. // This script uses the script TOESDIAL to log-on, which takes you to
  19. // the Bulletin menu. From there on this script automates the task of
  20. // uploading and downloading mail from an OPUS based BBS, using Silver Express
  21.  
  22. //
  23. // REMEMBER to compile any script files that you alter. This file can
  24. // be compiled by entering "CS TOES" at the DOS prompt.
  25. //
  26.  
  27. // See TOES.DOC for more information on the use of the script, and what
  28. // other requirements must be met, as well as the history of TOES, and
  29. // a list of files which should be in the distribution package
  30.  
  31. ///////////////////////////////////////////////////////////////////////////////
  32. // Possible Enhancements and known bugs :
  33. // As suggested by Lester Hanger : shorten waitfor's and tracks to try
  34. //   to prevent endless looping caused by corrupted strings sent.
  35. //   Alternatively, make it time based. If no response within the configured
  36. //   time, hang up automatically
  37. // Possibly cater for Expert as well as novice modes - both SX and OPUS
  38. // Add a facility to check for any .REP files other than the main one, and
  39. //   upload them too
  40. ///////////////////////////////////////////////////////////////////////////////
  41.  
  42. ////////////////////////////////////////////////////////////////////////////
  43. // USER SPECIFIC VARIABLES
  44. str my_screen_shows_color[1];
  45. str dial_str[10];
  46. str user_name[60];
  47. str toes_msg_file[12];
  48. str toes_rep_file[12];
  49. str my_reply_dir[60];
  50. str my_mail_dir[60];
  51. str make_date_packet[1];
  52. str zmodem_protocol[1];
  53. str auto_zap_opx[1];
  54. str i_send_password[1];
  55. str user_password[50];
  56. // END OF USER SPECIFIC VARIABLES
  57. ////////////////////////////////////////////////////////////////////////////
  58. int rep_ok;                            // Set by check_upload_dir()
  59.                                        // 0 = no reply file to upload
  60.                                        // 1 = there is a reply file to upload
  61. int tmark;   // a timer for auto bypass in check_dnload_dir
  62. str toes_rep_filespec[64];    //  moved these here so they will be global
  63. str toes_msg_filespec[64];    // to use from both check_upload_dir AND toes_go
  64. int t1, t2, t3, t4, t5, t6, t7, t8, stat;
  65. //  moved here to make them global to allow use in main as well as in toes_go
  66. int stat2; // used for tracking no new msgs and too many msgs
  67. int clean_exit = 0;   // test if we got prompt on attempt to exit
  68. str date_name[8] = "";  // global file name in YYMMDD format
  69. str screen_buffer[80] = "";  // added to allow concat of message + file
  70.                              // name for display
  71. int kount;                  // general purpose counter
  72. str search[80] = "";        // needed to search for existing
  73. str search2[80] = "";       // files for copying to date format
  74. str filefinder[] = "";      // file names
  75. str buffer[80];             // added for the OPUS / XPRESS file
  76. int file_handle;            //   changes
  77. str prompt[80];           // added to store expected prompt
  78. int chr = 0;
  79. int quit = 0;
  80. int time_delay, hour, min, shour, smin;
  81. str cnf_up_dir[80];
  82. str cnf_down_dir[80];
  83. str small[10];
  84. int protocol;
  85. ////////////////////////////////////////////////////////////////////////////
  86.  
  87. main()
  88. {
  89.   get_config();  // check for, and read a config file
  90.  
  91.   clear_scr();
  92.   prints("   ████████████████   ████████████████   ████████████████   ████████████████");
  93.   prints("          ██          ██            ██   ██                 ██            ██");
  94.   prints("          ██          ██            ██   ██                 ██");
  95.   prints("          ██          ██            ██   ██                 ██");
  96.   prints("          ██          ██            ██   ██████████         ████████████████");
  97.   prints("          ██          ██            ██   ██                               ██");
  98.   prints("          ██ Telix    ██    OPUS    ██   ██   Express            Script   ██");
  99.   prints("          ██          ██            ██   ██                 ██            ██");
  100.   prints("          ██          ████████████████   ████████████████   ████████████████");
  101.   prints("");
  102.   prints("");
  103.   prints("                         ┌───────────────────────────┐");
  104.   prints("                         │ ver *- 1.14 -* April 1991 │");
  105.   prints("                         └───────────────────────────┘");
  106.   prints("");
  107.   prints("                Originally written by Ken Ironside of 5:491/1");
  108.   prints("");
  109.   prints("             Currently maintained by Allan Marillier of 5:491/1");
  110.   prints("");
  111.   buffer = "Thank you for using TOES - ";
  112.   strcat(buffer,user_name);
  113.   strcat(buffer,".");
  114.   search = "                                         ";
  115.   inschrs(search,buffer,0,(80 - strlen(buffer))/2);
  116.   prints(buffer);
  117.   prints("                     We hope this script is useful to you !");
  118.   delay(40);
  119.  
  120.   // set up a loop to find if a time delay is required
  121.   tmark = timer_start(200);   // loop for 20 seconds
  122.   prints("Would you like to set a later time at which the script will begin ");
  123.   printsc("  polling the BBS ? (Yes / No / Abort) _ ");
  124.   quit = 0;
  125.   chr = 0;
  126.   _scr_chk_key = 0;
  127.   do
  128.   {
  129.     time_delay = toupper(inkey());
  130.     if (time_delay == 'Y' || time_delay == 'N' || time_delay == 'A')
  131.     {
  132.       quit = 1;
  133.       printc(time_delay);
  134.       prints("");
  135.     }
  136.     if (time_delay == 'A')
  137.       exittelix();
  138.     if (time_delay == 'Y')
  139.     {
  140.       // get current date
  141.       date(curtime(),search);
  142.       printsc("^M^JCurrent date is ");
  143.       prints(search);
  144.       // get the start time
  145.       date(curtime(),search);
  146.       time(curtime(),search);
  147.       printsc("Current time is : ");
  148.       prints(search);
  149.       prints("Enter the start time to begin polling (24 hour format - HH:MM)");
  150.       quit = 0;
  151.       do
  152.       {
  153.         gets(buffer,5);
  154.         // do validation of time
  155.         if (strchr(buffer,0,':') == 2)
  156.         {
  157.           subchrs(buffer,0,2,search);
  158.           subchrs(buffer,3,2,search2);
  159.           shour = stoi(search);
  160.           smin = stoi(search2);
  161.           if (shour >= 0 && shour <= 24 && smin >= 0 && smin <= 59)
  162.             quit = 1;
  163.           else
  164.             prints("^M^JInvalid time entered .... try again");
  165.         }
  166.       } while (quit == 0);
  167.     }
  168.   } while (quit == 0 && not time_up(tmark));
  169.   timer_free(tmark);
  170.   _scr_chk_key = 1;
  171.  
  172.   // do the delay if required
  173.   if (time_delay == 'Y')
  174.   {
  175.     t1 = _back_color;
  176.     t2 = _fore_color;
  177.     _back_color = 0;
  178.     _fore_color = 0;
  179.     _scr_chk_key = 0;
  180.     quit = 0;
  181.     chr = 0;
  182.     clear_scr();
  183.     do
  184.     {
  185.       chr = inkey();
  186.       if (chr)
  187.       {
  188.         chr = 0;
  189.         _back_color = t1;
  190.         _fore_color = t2;
  191.         clear_scr();
  192.         printsc("Abort, Continue to delay, Proceed immediately ? ( A / C / P ) ");
  193.         chr = toupper(inkeyw());
  194.         strupper(search);
  195.         if (chr == 'A')
  196.           exittelix();
  197.         if (chr == 'P')
  198.           quit = 1;
  199.         _back_color = 0;
  200.         _fore_color = 0;
  201.         chr = 0;
  202.       }
  203.       kount = curtime();
  204.       hour = thour(kount);
  205.       min = tmin(kount);
  206.       if (hour == shour && min == smin)
  207.         quit = 1;
  208.       else
  209.       {
  210.         // display a character somewhere
  211.         clear_scr();
  212.         gotoxy(tsec(kount),tsec(kount)/4);
  213.         vputchr(15 + 112 * 256);
  214.       }
  215.     } while (!quit);
  216.     clear_scr();
  217.     _back_color = t1;
  218.     _fore_color = t2;
  219.     _scr_chk_key = 1;
  220.   } // end if delay was required
  221.  
  222.   strcat(user_name,";y");
  223.  
  224.   if (zmodem_protocol == "D" || zmodem_protocol == "P")
  225.   // set z modem auto download off if external DSZ or PCZ is to be used
  226.     _zmod_auto = 0;
  227.  
  228.   // save the configured upload and download directories
  229.   cnf_up_dir = _up_dir;
  230.   cnf_down_dir = _down_dir;
  231.  
  232.   // pick up the user defined mail and reply directories.
  233.   _up_dir = my_reply_dir;
  234.   _down_dir = my_mail_dir;
  235.  
  236.   toes_rep_filespec = _up_dir;
  237.  
  238.   // check for, and add a trailing backslash, if none is found
  239.   if (subchr(toes_rep_filespec,strlen(toes_rep_filespec) - 1,1) != 92)
  240.     strcat(toes_rep_filespec,"\");
  241.   strcat(toes_rep_filespec,toes_rep_file);
  242.  
  243.   // function call to set date_name
  244.   set_date_name();
  245.  
  246.   terminal();                         // Keep processing input from the BBS
  247.   if (!check_dnload_dir())  // check download directory, check for exist OPX
  248.     exittelix(0,1);
  249.  
  250.   check_upload_dir();  // check for upload files
  251.   init_capture_file();  // open the log file
  252.   dial(dial_str,0);   // dial the BBS, and logon
  253.   // TOESDIAL will run here, if configured as the script to use in the
  254.   // dialling directory. It will take you to the Bulletin Menu on the BBSQyGolden City Fido.
  255.  
  256.   if (waitfor("Select:",30))          // Bulletin Menu prompt
  257.     cputs("Q^M");                    // Send "Q" for "Quit"
  258.   else
  259.   {
  260.      hangup();                       // If no prompt - bail out
  261.      exittelix(0,1);
  262.   }
  263.   if (waitfor("MAIN:",30))         // Main Opus menu
  264.   {
  265.     cputs("E^M");                    // Send 'E' for Silver Express
  266.     toes_go();                        // Run the SE procedure
  267.   }
  268.   else
  269.   {
  270.     hangup();                        // If no prompt - bail out
  271.     exittelix(0,1);
  272.   }
  273.  
  274.   t1 = track("MAIN:",0);
  275.   t2 = track("Password:",0);
  276.   // Anything else to be tracked can be put here if necessary
  277.   tmark = timer_start(600);
  278.   while (not time_up(tmark))     // wait for a prompt for up to 60 secs
  279.   {
  280.     terminal();
  281.     stat = track_hit(0);
  282.     if (stat == t1)
  283.     {
  284.       send_req();  // USE TOES.REQ here - note ! this is AFTER sx up/download
  285.       clean_exit = 1;
  286.       cputs("G^M");                    // Goodbye
  287.       goodbye_fido();                  // Run the Clean Exit From Fido Proc
  288.       break;                           // break out of this while loop
  289.     }
  290.     if (stat == t2)  // cater for the possibility that Dave
  291.                      // re-introduces forced password on re-entry from SE
  292.     {
  293.       cputs (_entry_pass);
  294.       cputs ("^M");
  295.     }
  296.   }
  297.   timer_free(tmark);                  // free the timer
  298.   track_free(0);                      // free up the tracking
  299.   if (clean_exit == 0)
  300.     hangup();                         // If no prompt - bail out
  301.   exittelix(0,1);                     // exit telix
  302. }                                    // End of Main()
  303. ////////////////////////////////////////////////////////////////////////////
  304. check_dnload_dir()
  305. {
  306.   str buffer[64];
  307.   int video_buffer_handle;
  308.  
  309.   int pos;
  310.  
  311.   int sound_state;    // save the state of the sound setting
  312.   int disp_color;     // added this for setting display colours
  313.   if (my_screen_shows_color == "Y")
  314.     disp_color = (12 + (16 * 01) ) * 256;  // calculate the constant
  315.     // 12 = Light Red, 16 * 01 = Blue background, vputchr wants this * 256
  316.   else
  317.     disp_color = (15 * 256);
  318.     // 15 = white, 16 * 0 = black background, * 256 for vputchr
  319.  
  320.   if (_zmod_rcrash != 0)
  321.   // This section is only important if crash recovery is enabled
  322.   {
  323.     toes_msg_filespec = _down_dir;
  324.  
  325.     // check for, and add a trailing backslash, if none is found
  326.     if (subchr(toes_msg_filespec,strlen(toes_msg_filespec) - 1,1) != 92)
  327.       strcat(toes_msg_filespec,"\");
  328.  
  329.     // make it ignore keyboard for Esc to abort script
  330.     _scr_chk_key = 0;
  331.  
  332.     strcat(toes_msg_filespec,toes_msg_file);
  333.     if (filefind(toes_msg_filespec,0,buffer))
  334.     // if the file exists then the user must choose something
  335.     {
  336.       if (auto_zap_opx == "Y")
  337.         fdelete(toes_msg_filespec);  // delete the file
  338.       else
  339.       {
  340.         video_buffer_handle = vsavearea(15,7,65,16);   // save what is under
  341.                                                        // the window
  342.         box(15,7,65,16,1,0,31);                     // 31 = White on Blue
  343.         scroll(16,8,64,15,8,7);
  344.         gotoxy(17,8);
  345.  
  346.         buffer = toes_msg_file;
  347.         strcat(buffer," already exists in download directory");
  348.         printsc(buffer);
  349.         gotoxy(17,10);
  350.         vputchr('R' + disp_color); // "R" in red on blue
  351.         gotoxy(18,10);
  352.         printsc("ename to .BAK (current dir NOT d/l dir (v 3.12))");
  353.         gotoxy(17,11);
  354.         vputchr('D' + disp_color); // "D" in red on blue
  355.         gotoxy(18,11);
  356.         printsc("elete it");
  357.         gotoxy(17,12);
  358.         vputchr('I' + disp_color); // "I" in red on blue
  359.         gotoxy(18,12);
  360.         printsc("gnore it");
  361.         gotoxy(17,13);
  362.         vputchr('Q' + disp_color); // "Q" in red on blue
  363.         gotoxy(18,13);
  364.         printsc("uit the session");
  365.         tmark = timer_start(600);
  366.         // set up for 60 second delay before auto decide what to do
  367.         chr = 0;
  368.         do
  369.         {
  370.           gotoxy(17,15);
  371.           printsc("Select:  ");
  372.           gotoxy(25,15);
  373.           chr = toupper(inkey());
  374.           // allow looping to test countdown
  375.           printc(chr);
  376.           if ((chr == 82) or (chr == 68) or (chr == 73) or (chr == 81))
  377.           {
  378.             quit = 1;
  379.             break;    // break out of the loop
  380.           }
  381.           else
  382.           if (chr > 0)   // turn sound on, and beep
  383.           {
  384.             sound_state = _sound_on;
  385.             _sound_on = 1;
  386.             tone(659,14);
  387.             _sound_on = sound_state;
  388.           }
  389.           // show user countdown status
  390.           gotoxy(55,15);
  391.           if (timer_total(tmark) > 510)
  392.           {
  393.             printn(0);
  394.             gotoxy(56,15);
  395.           }
  396.           printn(60 - (timer_total(tmark) / 10));
  397.         } while (quit == 0 && not time_up(tmark));
  398.         timer_free(tmark);   // free the timer variable
  399.         // must now make it ignore if no manual intervention
  400.         if (quit == 0)
  401.         {
  402.           chr = 73;              // put I in, to ignore
  403.           _zmod_rcrash = 0;
  404.           // turn z modem crash recovery OFF. This way, if the .OPX file
  405.           // exists, it will create a files .OP0, .OP1 etc..... but ONLY for
  406.           // Telix' internal Zmodem. For DSZ / PCZ users, we must get rid of the
  407.           // file, or DSZ will hang, therefore simulate user requesting Rename
  408.           if (zmodem_protocol == "D" || zmodem_protocol == "P")
  409.             chr = 82;
  410.         }
  411.         vrstrarea(video_buffer_handle);     // Clear the window
  412.         if (chr == 82)          // Rename
  413.         {
  414.           buffer = toes_msg_file;
  415.           pos = strpos(buffer,".",0);
  416.           delchrs(buffer,(pos+1),3);
  417.           strcat(buffer,"BAK");
  418.           frename(toes_msg_filespec,buffer);
  419.           // this frename has the effect of MOVING the file to a
  420.           // .BAK in the current dir with v 3.12. Fixed in v 3.15
  421.           return(1);
  422.         }
  423.         else
  424.         if (chr == 68)        // Delete
  425.         {
  426.           fdelete(toes_msg_filespec);
  427.           return(1);
  428.         }
  429.         else
  430.         if (chr == 73)      // Ignore
  431.         {
  432.           //  we can't just ignore though, because we will corrupt
  433.           // the file GCOBBS.OPX. The reason we test here for the file, is
  434.           // because zmodem crash recovery is on, and that is critical.
  435.           // If the user manually chooses to Ignore, then we MUST set
  436.           // zmodem crash recovery off, so the file will be named .OP1, .OP2 ...
  437.           _zmod_rcrash = 0;
  438.           return(1);
  439.         }
  440.         else                  // Quit
  441.         {
  442.           return(0);
  443.         }
  444.       } // end if using internal zmodem
  445.     } // end if an old opx is found to exist
  446.   }  // end if zmodem crash recovery is on
  447.   else
  448.     prints("No mail file currently exists in the download area ....");
  449.   // re-enable Esc to allow aborting script by Esc
  450.   _scr_chk_key = 1;
  451. }   // end function check_dnload_dir
  452. ////////////////////////////////////////////////////////////////////////////
  453. check_upload_dir()
  454. // This proc checks the upload directory for the reply file.
  455. // If it exists, then it sets rep_ok to 1. If not, rep_ok is set to 0
  456. {
  457.   str buffer[64];
  458.  
  459.   if (filefind(toes_rep_filespec,0,buffer))   // if the file exists then the
  460.   {
  461.     rep_ok = 1;
  462.     prints("There is a reply file to upload...");
  463.   }
  464.   else
  465.   {
  466.     rep_ok = 0;
  467.     prints("There is no reply file to upload...");
  468.   }
  469. }   // end function check_upload_dir
  470. ////////////////////////////////////////////////////////////////////////////
  471. init_capture_file()      // Function to open a capture file in the
  472.                          // format "YYMMDD.LOG"
  473. {
  474.   // replaced original with new code, at Pat Verner's suggestion
  475.   // to write log file to YYMMDD.LOG, and not CAPnn
  476.   // note - global variable date_name is set by function set_date_name
  477.  
  478.   str s1[16];          // To hold the capture file name
  479.   str s2[4] = ".LOG";  // Capture File type
  480.  
  481.   s1 = date_name;
  482.   strcat(s1,s2);
  483.   screen_buffer = "A record of this session will be contained in file ";
  484.   strcat(screen_buffer,s1);
  485.   prints(screen_buffer);
  486.   capture(s1);
  487.   update_term();
  488. }  // end function init_capture_file
  489. ////////////////////////////////////////////////////////////////////////////
  490. toes_go()                               // This is the Silver Express Module
  491. {
  492.   int dn_ok = 1;                      // download flag. 1 = no download has
  493.                                      // taken place yet. 0 = download complete
  494.  
  495.   int video_buffer_handle;            // if we need a message box, this is
  496.                                       // required.
  497.   int sound_stat;                     // hold temp _sound_on variable
  498.   str buffer[64];         // needed by FileFind function
  499.  
  500.   t1 = track("[ Press Any Key to Continue ]",0);
  501.   t2 = track("Enter C, D, U, S, H, Q ?",0);   // changed for new SX prompts
  502.   t3 = track("No New Messages to Download!",0); // followed by t1
  503.   t4 = track("Message Limit Exceeded",0);
  504.   t5 = track("Press [CR] Download, [ESC] Abort",0);
  505.   t6 = track("Enter Flex Select <tm>",0);
  506.   t7 = track("Enter Selection:",0);
  507.   t8 = track("More",0);
  508.   int copy_error = 0;   // added as error checking for copy via dos, of
  509.                         // duplicate date named file
  510.  
  511.   while (1)
  512.   {
  513.     terminal();
  514.     stat = track_hit(0);
  515.     if (stat == t7)
  516.       cputs("Y^M");
  517.     if (stat == t1)
  518.       cputs("^M");
  519.     else
  520.     if (stat == t2 || stat == t7)  // "Enter C, D, U, S, H, Q ?"
  521.     {
  522.       if (rep_ok == 1)            // There's a file to upload
  523.       {
  524.         cputs("U^M");            // Send 'U' for upload
  525.         delay_scr(40);           // Wait 4 seconds
  526.         if (zmodem_protocol == "D")
  527.           dos("toesdsnd.bat",0);
  528.         else
  529.         if (zmodem_protocol == "P")
  530.           dos("toespsnd.bat",0);
  531.         else
  532.         {
  533.           kount = send('Z',toes_rep_file);  // Send the reply file
  534.           if (kount == -1)  // transfer was aborted - try again with DSZ / PCZ
  535.           {
  536.             if (filefind("PCZ.EXE",2,buffer))
  537.             {
  538.               zmodem_protocol = "P";
  539.               cputs("U^M");            // Send 'U' for upload
  540.               delay_scr(40);           // Wait 4 seconds
  541.               dos("toespsnd.bat",0);
  542.             }
  543.             else
  544.             if (filefind("DSZ.EXE",2,buffer))
  545.             {
  546.               zmodem_protocol = "D";
  547.               cputs("U^M");            // Send 'U' for upload
  548.               delay_scr(40);           // Wait 4 seconds
  549.               dos("toesdsnd.bat",0);
  550.             }
  551.             else
  552.             {
  553.               // neither was available - send Q, and break out
  554.               search = date_name;
  555.               strcat(search,".LOG");
  556.               file_handle = fopen(search,"a");
  557.               fputs("",file_handle);
  558.               fputs("*********************************************",file_handle);
  559.               fputs("WARNING ! Reply UPLOAD failed. Internal Zmodem aborted.",file_handle);
  560.               fputs("  An attempt was made to use either PCZ.EXE or DSZ.EXE.",file_handle);
  561.               fputs("  but neither program could be found in the current directory.",file_handle);
  562.               fputs("TOES panic abort !",file_handle);
  563.               fputs("*********************************************",file_handle);
  564.               fclose(file_handle);
  565.               cputs("Q^M");  // send quit to exit Silver Express, back to BBS
  566.               break;
  567.             }
  568.             continue;
  569.           }
  570.           if (kount == -2)  // carrier was lost
  571.           {
  572.             search = date_name;
  573.             strcat(search,".LOG");
  574.             file_handle = fopen(search,"a");
  575.             fputs("",file_handle);
  576.             fputs("*********************************************",file_handle);
  577.             fputs("WARNING ! Carrier was lost during upload.",file_handle);
  578.             fputs("TOES panic abort !",file_handle);
  579.             fputs("*********************************************",file_handle);
  580.             fclose(file_handle);
  581.             hangup();
  582.             exittelix();
  583.           }
  584.         }
  585.         if (zmodem_protocol != "I" || waitfor("Successful Transfer!",60))
  586.         {
  587.           rep_ok = 0;
  588.           // If successful, set rep_ok to 0 so it won't try to send again
  589.           // and then also delete the file afterwards
  590.           fdelete(toes_rep_filespec);
  591.         }
  592.         continue;
  593.       }
  594.       if (dn_ok == 1)           // We have not downloaded yet
  595.       {
  596.         cputs("D^M");          // Send 'D' to download
  597.         while(1)
  598.         {
  599.           terminal();
  600.           stat = track_hit(0);
  601.           if (stat == t1 || stat == t3 || stat == t4) // no new, or > 500 msgs
  602.           {
  603.             cputs("^M");
  604.             dn_ok = 0;                // Set the download complete flag so it
  605.                                       // won't try to download again.
  606.             break;                    // break out
  607.           }
  608.           else
  609.           if (stat == t6)
  610.           {
  611.             cputs("A^M");  // OK - send A for all
  612.             break;         // break out
  613.           }
  614.         }
  615.         continue;
  616.       }
  617.       // If both upload and download are complete, then send quit, and
  618.       // then break out of the while loop to exit toes_go
  619.       if (rep_ok == 0 && dn_ok == 0)
  620.       {
  621.         cputs("Q^M");  // send quit to exit Silver Express, back to BBS
  622.         break;
  623.       }
  624.     }
  625.     else
  626.     if ((stat == t5) and (dn_ok == 1))  // "Press ENTER to start Download or ESC to abort."
  627.     {
  628.       cputs("^M");                     // Send a cr
  629.       if (zmodem_protocol == "D")
  630.       {
  631.         if (waitfor("Start Your System to Download the File with Z-Modem",15))
  632.           { }; // do nothing - just wait for the silly message
  633.         dos("toesdget.bat",0);
  634.         cputs("^M^M^M");   // DSZ has a problem returning - possibly
  635.                            // speed related, so send a few CRs, then test
  636.                            // for SX temporarily assigning novice mode
  637.       }
  638.       else
  639.       if (zmodem_protocol == "P")
  640.       {
  641.         if (waitfor("Start Your System to Download the File with Z-Modem",15))
  642.           { }; // do nothing - just wait for the silly message
  643.         dos("toespget.bat",0);
  644.         // cputs("^M^M^M");   // DSZ has a problem returning - possibly
  645.                            // speed related, so send a few CRs, then test
  646.                            // for SX temporarily assigning novice mode
  647.       }
  648.       else
  649.       {
  650.         if (_zmod_auto == 0 && zmodem_protocol = "I") // if z modem auto
  651.         {                           // receive is off, bypass that and initiate a
  652.           kount = receive('Z',"");  // receive from here
  653.           if (kount == -1)  // transfer was aborted - try again with DSZ
  654.           {
  655.             if (filefind("PCZ.EXE",2,buffer))
  656.             {
  657.               zmodem_protocol = "P";
  658. // dos("toespget.bat",0);
  659. // leave this, as a failed transfer will cause dn_ok to be left at 1, therefore
  660. // it will try again
  661.             }
  662.             else
  663.             if (filefind("DSZ.EXE",2,buffer))
  664.             {
  665.               zmodem_protocol = "D";
  666. // dos("toesdget.bat",0);
  667. // leave this, as a failed transfer will cause dn_ok to be left at 1, therefore
  668. // it will try again
  669.             }
  670.  
  671. // ALLAN
  672. // else ? what if neither is available then I must recover somehow
  673. // ie. write a message and hangup
  674.  
  675.             continue;
  676.           }
  677.           if (kount == -2)  // carrier was lost
  678.           {
  679.             search = date_name;
  680.             strcat(search,".LOG");
  681.             file_handle = fopen(search,"a");
  682.             fputs("",file_handle);
  683.             fputs("*********************************************",file_handle);
  684.             fputs("WARNING ! Carrier was lost during download.",file_handle);
  685.             fputs("TOES panic abort !",file_handle);
  686.             fputs("*********************************************",file_handle);
  687.             fclose(file_handle);
  688.             hangup();
  689.             exittelix();
  690.           }
  691.         }
  692.       }
  693.       if (waitfor("Successful Transfer!",10) || zmodem_protocol == "D" || zmodem_protocol == "P")
  694.       // assume that if DSZ is used, then the message will be missed, and
  695.       // assume that transfer WAS ok. Put simply - if there is a problem
  696.       // with DSZ, it probably won't return properly anyway.
  697.       {
  698.         dn_ok = 0;              // Set the download complete flag so it
  699.                                // won't try to download again.
  700.         // make a backup file if necessary
  701.         if (make_date_packet == "Y")
  702.         {
  703.           // check for existing files
  704.           kount = 0;
  705.           search = _down_dir;
  706.           strcat(search,date_name);
  707.           search2 = search;
  708.           strcat(search2,"00.OPX");
  709.           while (filefind(search2,0,buffer))
  710.           {
  711.             kount = kount + 1;
  712.             search2 = search;
  713.             if (kount < 10)
  714.               strcat(search2,"0");
  715.             itos(kount,buffer);
  716.             strcat(search2,buffer);
  717.             strcat(search2,".OPX");
  718.           }
  719.           screen_buffer = "copy ";
  720.           strcat(screen_buffer,toes_msg_filespec);
  721.           strcat(screen_buffer," ");
  722.           strcat(screen_buffer,_down_dir);
  723.           strcat(screen_buffer,date_name);
  724.           if (kount < 10)
  725.             strcat(screen_buffer,"0");
  726.           itos(kount,search);
  727.           strcat(screen_buffer,search);
  728.           strcat(screen_buffer,".OPX");
  729.           copy_error = dos(screen_buffer,0);
  730.           search = date_name;
  731.           strcat(search,".LOG");
  732.           file_handle = fopen(search,"a");
  733.           fputs("",file_handle);
  734.           fputs("*********************************************",file_handle);
  735.           // test for not enough memory
  736.           if (copy_error == -1)
  737.           {
  738.             fputs("Can't run a DOS shell to copy the backup file",file_handle);
  739.             fputs("Either there isn't enough memory, OR command.com",file_handle);
  740.             fputs("can't be found.",file_handle);
  741.           }
  742.           else
  743.             fputs("Date named backup made successfully ....",file_handle);
  744.           fputs("*********************************************",file_handle);
  745.           fputs("",file_handle);
  746.           fclose(file_handle);
  747.         }
  748.       }
  749.     }
  750.   }
  751.   track_free(0);                      // Free up the tracking
  752. }  // end function toes_go
  753. ////////////////////////////////////////////////////////////////////////////
  754. goodbye_fido()                         // This is the Clean Exit From Fido
  755.                                        // Procedure
  756. {
  757.   if (waitfor("Disconnect [Y,n,?=help]?",20))
  758.   {
  759.     cputs("^M");               // Disconnect
  760.     if (waitfor("Leave a note to Dave Pedler [y,N,?=help]?",20))
  761.     {
  762.       cputs("^M");            // You don't want to talk to Dave do you?
  763.       delay_scr(60);          // If you are not getting the whole logoff
  764.                               // message, increase this value in 1/10ths
  765.                               // of a second, and vice versa.
  766.       return(1);
  767.     }
  768.     else
  769.       goto gone;
  770.   }
  771.   else
  772.     goto gone;
  773.   gone:
  774.  
  775.   {
  776.     hangup();
  777.     exittelix(0,1);
  778.   }
  779. }   // end function goodbye_fido
  780. ////////////////////////////////////////////////////////////////////////////
  781. set_date_name()
  782. // function to read date and set variable date_name in YYMMDD format
  783. {
  784.   str dat[4];           // temp to hold dates
  785.   int temp;            // Temp variable to hold the numeric date value
  786.  
  787.   temp = curtime();
  788.   itos(tyear(temp),dat);
  789.   strcat (date_name,dat);
  790.   delchrs(date_name,0,2);   // remove the century digits
  791.   itos(tmonth(temp),dat);
  792.   if (tmonth(temp) < 10)  // precede 1 to 9 with 0
  793.     strcat(date_name,"0");
  794.   strcat (date_name,dat);
  795.   itos(tday(temp),dat);
  796.   if (tday(temp) < 10)  // precede 1 to 9 with 0
  797.     strcat(date_name,"0");
  798.   strcat (date_name,dat);
  799. }   // end set_date_name
  800. ////////////////////////////////////////////////////////////////////////////
  801. get_config()
  802. // check for and read the config file. If none exists, create it
  803. // using the defaults, and allow editing
  804. {
  805.   if (filefind("TOES.CNF",3,buffer) != 0)
  806.   {
  807.     // it exists, so read it
  808.     // if it doesn't exist, return to main. set_config will create it
  809.     file_handle = fopen("TOES.CNF","r");
  810.     // get value for colour screen
  811.     buffer = "";
  812.     if (fgets(buffer,3,file_handle) == -1)
  813.     {
  814.        fclose(file_handle);
  815.        panic();
  816.      }
  817.      strupper(buffer);
  818.      if (buffer == "Y" || buffer =="N")
  819.        my_screen_shows_color = buffer;
  820.  
  821.      // get value for dial string
  822.      buffer = "";
  823.      if (fgets(buffer,80,file_handle) == -1)
  824.      {
  825.        fclose(file_handle);
  826.        panic();
  827.      }
  828.      strupper(buffer);
  829.      dial_str = buffer;
  830.      // how do I check this ? I think that's the user's responsibility
  831.  
  832.      // get value for user_name
  833.      buffer = "";
  834.      if (fgets(buffer,80,file_handle) == -1)
  835.      {
  836.        fclose(file_handle);
  837.        panic();
  838.      }
  839.      strupper(buffer);
  840.      user_name = buffer;
  841.      // strcat(user_name,";y"); - only necessary for TOES itself
  842.  
  843.      // get value for toes_msg_file
  844.      buffer = "";
  845.      if (fgets(buffer,80,file_handle) == -1)
  846.      {
  847.        fclose(file_handle);
  848.        panic();
  849.      }
  850.      strupper(buffer);
  851.      toes_msg_file = buffer;
  852.  
  853.      // get value for toes_rep_file
  854.      buffer = "";
  855.      if (fgets(buffer,80,file_handle) == -1)
  856.      {
  857.        fclose(file_handle);
  858.        panic();
  859.      }
  860.      strupper(buffer);
  861.      toes_rep_file = buffer;
  862.  
  863.      // get value for my_reply_dir
  864.      buffer = "";
  865.      if (fgets(buffer,80,file_handle) == -1)
  866.      {
  867.        fclose(file_handle);
  868.        panic();
  869.      }
  870.      strupper(buffer);
  871.      my_reply_dir = buffer;
  872.  
  873.      // get value for my_mail_dir
  874.      buffer = "";
  875.      if (fgets(buffer,80,file_handle) == -1)
  876.      {
  877.        fclose(file_handle);
  878.        panic();
  879.      }
  880.      strupper(buffer);
  881.      my_mail_dir = buffer;
  882.  
  883.      // get value for make_date_packet
  884.      buffer = "";
  885.      if (fgets(buffer,3,file_handle) == -1)
  886.      {
  887.        fclose(file_handle);
  888.        panic();
  889.      }
  890.      strupper(buffer);
  891.      if (buffer == "Y" || buffer == "N")
  892.        make_date_packet = buffer;
  893.  
  894.      // get value for zmodem_protocol
  895.      buffer = "";
  896.      if (fgets(buffer,3,file_handle) == -1)
  897.      {
  898.        fclose(file_handle);
  899.        panic();
  900.      }
  901.      strupper(buffer);
  902.      if (buffer == "I" || buffer == "D" || buffer == "P")
  903.        zmodem_protocol = buffer;
  904.  
  905.      // get value for auto_zap_opx
  906.      buffer = "";
  907.      if (fgets(buffer,3,file_handle) == -1)
  908.      {
  909.        fclose(file_handle);
  910.        panic();
  911.      }
  912.      strupper(buffer);
  913.      if (buffer == "Y" || buffer == "N")
  914.        auto_zap_opx = buffer;
  915.  
  916.      // get value for i_send_password
  917.      buffer = "";
  918.      if (fgets(buffer,3,file_handle) == -1)
  919.      {
  920.        fclose(file_handle);
  921.        panic();
  922.      }
  923.      strupper(buffer);
  924.      if (buffer == "Y" || buffer == "N")
  925.        i_send_password = buffer;
  926.  
  927.      // get value for user_password
  928.      buffer = "";
  929.      if (fgets(buffer,53,file_handle) == -1)
  930.      {
  931.        fclose(file_handle);
  932.        panic();
  933.      }
  934.      strupper(buffer);
  935.      user_password = buffer;
  936.  
  937.     fclose(file_handle);
  938.   }
  939.   else
  940.   {
  941.     clear_scr();
  942.     prints("There is a problem ! The configuration file TOES.CNF does not");
  943.     prints("exist. Please enter all relevant details when the configuration");
  944.     prints("script is activated.");
  945.     delay(50);
  946.     call("TOES_CFG");
  947.     if (filefind("TOES.CNF",3,buffer) != 0)
  948.       get_config();
  949.     else
  950.       panic();
  951.   }
  952. } // end function get_config
  953. ////////////////////////////////////////////////////////////////////////////
  954. panic()
  955. {
  956.   // panic exit from get_config - due to corrupt file etc.
  957.   prints("PANIC exit from TOES script attempting to read the config file");
  958.   prints("  TOES.CNF. Something is wrong ! The file is corrupt, or otherwise");
  959.   prints("  inaccessible. If it exists, try deleting it. This script will ");
  960.   prints("  automatically recreate it. If that fails, try viewing it. It ");
  961.   prints("  should appear in the format shown below :");
  962.   prints("N");
  963.   prints("1 2");
  964.   prints("Jan Pierewiet");
  965.   prints("GCOBBS.OPX");
  966.   prints("GCOBBS.REP");
  967.   prints("C:\XPRESS\REPLY\");
  968.   prints("C:\XPRESS\MAIL\");
  969.   prints("N");
  970.   prints("I");
  971.   prints("Y");
  972.   prints("N");
  973.   prints("Choose_a_password:-50_chars");
  974.   prints("");
  975.   prints(" If errors persist - please contact Allan Marillier at 5:491/1");
  976.   delay(150);
  977.   fclose(file_handle);
  978.   exittelix();
  979. } // end function panic
  980. ////////////////////////////////////////////////////////////////////////////
  981. send_req()
  982. // function to check for a request file, read and act on it's contents
  983. {
  984.  
  985.   int transferring = 0;
  986.   int bat_handle;
  987.  
  988.   // turn auto zmodem transfers back on if Internal Zmodem is used
  989.   // because it's needed for up/downloads
  990.   if (zmodem_protocol == "I")
  991.     _zmod_auto = 1;
  992.  
  993.   // reset the upload and download directories
  994.   _up_dir = cnf_up_dir;
  995.   _down_dir = cnf_down_dir;
  996.  
  997.   if (filefind("TOES.REQ",2) != 0)  // check if the file exists
  998.   {
  999.     file_handle = fopen("TOES.REQ","r");  // open it and get file handle
  1000.     prompt = "Select:";
  1001.     buffer = "";
  1002.     while (buffer != "$FINISHED$") // loop until end of file
  1003.     {
  1004.       if (transferring)
  1005.       {
  1006.         waitfor(prompt,36000);
  1007.         transferring = 0;
  1008.       }
  1009.       else
  1010.         waitfor(prompt,3600);
  1011.       fgets(buffer,80,file_handle);  // read the file for request
  1012.       fgets(prompt,80,file_handle);  // read again for expected prompt
  1013.       if (buffer != "$FINISHED$") // loop until end of file
  1014.       {
  1015.         if (strpos(buffer,"$FILE_",0) == 0)
  1016.         // file transfer request - activate with relevant protocol
  1017.         {
  1018.           transferring = 1;
  1019.           // now find, is it an upload/download, and which protocol ?
  1020.           if (strpos(buffer,"SEND$",0) == 6)
  1021.           // send a file
  1022.           {
  1023.             delchrs(buffer,0,12);  // remove "$FILE_SEND$ "
  1024.             if (subchr(buffer,0) == 'Z' && zmodem_protocol != "I")
  1025.             // Zmodem transfer, NOT internal
  1026.             {
  1027.               delchrs(buffer,0,2);         // strip protocol + blank
  1028.               // normal call to dos can't pass parameters
  1029.               // therefore, we must create a batch file with the necessary
  1030.               // commands, to be called directly
  1031.               bat_handle = fopen("TOESTEMP.BAT","w");
  1032.               if (zmodem_protocol == "D")
  1033.               // DSZ
  1034.               {
  1035.                 search = "dsz handshake both port ";
  1036.                 itos(get_port(),small);
  1037.                 strcat(search,small);
  1038.                 strcat(search," speed ");
  1039.                 itos(get_baud(),small);
  1040.                 strcat(search,small);
  1041.                 strcat(search," sz ");
  1042.                 strcat(search,buffer);
  1043.                 fputs(search,bat_handle);
  1044.               }
  1045.               else
  1046.               // PCZ
  1047.               {
  1048.                 search = "pcz ";
  1049.                 itos(get_port(),small);
  1050.                 strcat(search,small);
  1051.                 strcat(search," ");
  1052.                 itos(get_baud(),small);
  1053.                 strcat(search,small);
  1054.                 strcat(search," sz ");
  1055.                 strcat(search,buffer);
  1056.                 fputs(search,bat_handle);
  1057.               }
  1058.               fclose(bat_handle);
  1059.               dos("TOESTEMP.BAT",0);
  1060.               fdelete("TOESTEMP.BAT");
  1061.               if (zmodem_protocol == "P")
  1062.                 delay(50);  // delay 5 seconds after a PCZ transfer, as it
  1063.                 // appears to be a bit slow in returning
  1064.             }
  1065.             else
  1066.             // ANY other INTERNAL transfer
  1067.             {
  1068.               copychrs(buffer,small,0,1);  // get protocol out
  1069.               delchrs(buffer,0,2);         // strip protocol + blank
  1070.               ctoi();  // convert protocol to int
  1071.               send(protocol,buffer);       // activate telix transfer
  1072.             }
  1073.             continue;
  1074.           }  // end if SEND
  1075.           else
  1076.           // receive a file
  1077.           {
  1078.             delchrs(buffer,0,15);  // remove "$FILE_RECEIVE$ "
  1079.             if (subchr(buffer,0) == 'Z' && zmodem_protocol != "I")
  1080.             // Zmodem transfer, NOT internal
  1081.             {
  1082.               delchrs(buffer,0,2);         // strip protocol + blank
  1083.               // normal call to dos can't pass parameters
  1084.               // therefore, we must create a batch file with the necessary
  1085.               // commands, to be called directly
  1086.               bat_handle = fopen("TOESTEMP.BAT","w");
  1087.               if (zmodem_protocol == "D")
  1088.               // DSZ
  1089.               {
  1090.                 search = "dsz handshake both port ";
  1091.                 itos(get_port(),small);
  1092.                 strcat(search,small);
  1093.                 strcat(search," speed ");
  1094.                 itos(get_baud(),small);
  1095.                 strcat(search,small);
  1096.                 strcat(search," rz ");
  1097.                 strcat(search,_down_dir);
  1098.                 strcat(search," ");
  1099.                 strcat(search,buffer);  // not necessary on receive
  1100.                 fputs(search,bat_handle);
  1101.               }
  1102.               else
  1103.               // PCZ
  1104.               {
  1105.                 search = "pcz ";
  1106.                 itos(get_port(),small);
  1107.                 strcat(search,small);
  1108.                 strcat(search," ");
  1109.                 itos(get_baud(),small);
  1110.                 strcat(search,small);
  1111.                 strcat(search," rz ");
  1112.                 strcat(search,_down_dir);
  1113.                 strcat(search," ");
  1114.                 strcat(search,buffer); // not necessary on receive
  1115.                 fputs(search,bat_handle);
  1116.               }
  1117.               fclose(bat_handle);
  1118.               dos("TOESTEMP.BAT",0);
  1119.               fdelete("TOESTEMP.BAT");
  1120.               if (zmodem_protocol == "P")
  1121.                 delay(50);  // delay 5 seconds after a PCZ transfer, as it
  1122.                 // appears to be a bit slow in returning
  1123.               continue;
  1124.             }
  1125.             else
  1126.             // ANY other INTERNAL transfer
  1127.             {
  1128.               copychrs(buffer,small,0,1);  // get protocol out
  1129.               delchrs(buffer,0,2);         // strip protocol + blank
  1130.               ctoi();      // convert protocol to int
  1131.               receive(protocol,buffer);       // activate telix transfer
  1132.             }
  1133.           }  // end if RECEIVE
  1134.         }  // end if file transfer request
  1135.         else
  1136.         {
  1137.           if (buffer == "$ENTER$")
  1138.           {
  1139.             cputs("^M");
  1140.           }
  1141.           else
  1142.           // normal request - send to BBS as a string
  1143.           {
  1144.             cputs(buffer);         // if not eof, then send string to BBS
  1145.             cputs("^M");
  1146.           }  // end if normal request
  1147.         } // end if other than file transfer
  1148.       }  // end test for not end of file
  1149.     }  // end while not eof
  1150.     fdelete("TOES.REQ");   // now tidy up by deleting the request file
  1151.   }  // end if TOES.REQ file exists
  1152. } // end function send_req
  1153. ////////////////////////////////////////////////////////////////////////////
  1154. ctoi()
  1155. // crude function to convert a character to an integer (ASCII) equivalent
  1156. {
  1157.   if (small == "A")
  1158.     protocol = 'A';
  1159.   if (small == "B")
  1160.     protocol = 'B';
  1161.   if (small == "C")
  1162.     protocol = 'C';
  1163.   if (small == "D")
  1164.     protocol = 'D';
  1165.   if (small == "E")
  1166.     protocol = 'E';
  1167.   if (small == "F")
  1168.     protocol = 'F';
  1169.   if (small == "G")
  1170.     protocol = 'G';
  1171.   if (small == "H")
  1172.     protocol = 'H';
  1173.   if (small == "I")
  1174.     protocol = 'I';
  1175.   if (small == "J")
  1176.     protocol = 'J';
  1177.   if (small == "K")
  1178.     protocol = 'K';
  1179.   if (small == "L")
  1180.     protocol = 'L';
  1181.   if (small == "M")
  1182.     protocol = 'M';
  1183.   if (small == "N")
  1184.     protocol = 'N';
  1185.   if (small == "O")
  1186.     protocol = 'O';
  1187.   if (small == "P")
  1188.     protocol = 'P';
  1189.   if (small == "Q")
  1190.     protocol = 'Q';
  1191.   if (small == "R")
  1192.     protocol = 'R';
  1193.   if (small == "S")
  1194.     protocol = 'S';
  1195.   if (small == "T")
  1196.     protocol = 'T';
  1197.   if (small == "U")
  1198.     protocol = 'U';
  1199.   if (small == "V")
  1200.     protocol = 'V';
  1201.   if (small == "W")
  1202.     protocol = 'W';
  1203.   if (small == "X")
  1204.     protocol = 'X';
  1205.   if (small == "Y")
  1206.     protocol = 'Y';
  1207.   if (small == "Z")
  1208.     protocol = 'Z';
  1209. } // end function ctoi
  1210. ////////////////////////////////////////////////////////////////////////////
  1211.